package com.tianyi.sfzy1.service;

import com.tianyi.sfzy1.domain.Chargeassociation;
import com.tianyi.sfzy1.mapper.ChargeassociationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChargeAssociationService {
    @Autowired
    private ChargeassociationMapper chargeassociationMapper;

//    遍历list集合 对集合中每一个Chargeassociation都执行insertOrUpdateChargeAssociation方法
    public int insertOrUpdateChargeAssociation(List<Chargeassociation> records){
        int successCount = 0;
        for (Chargeassociation record : records) {
            try {
                // 假设insertOrUpdateChargeAssociation返回受影响的行数
                int result = chargeassociationMapper.insertOrUpdateChargeAssociation(record);
                if (result > 0) {
                    successCount++;
                }
            } catch (Exception e) {
                // 这里应该有适当的错误处理逻辑
                // 比如日志记录、事务回滚等
                e.printStackTrace();
            }
        }
        return successCount;
    }
}
